/* $RCSFile: PageKeyPhrase.ascx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/PageModules/PageKeyPhrase/PageKeyPhrase.ascx.cs $
 * $log$
 * Revision 20 2010/08/09 10:51:21  christian.surieux
 *   Added Log comment to all .aspx .ascx .master files
 * Revision 19 2010/08/09 09:43:57  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:26  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Data;
using System.IO;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

using AddonNice.Diagnostics;
using AddonNice.UI.WebControls;
using AddonNice.Configuration;
using AddonNice.Configuration.Settings;
using AddonNice.UI.DataTypes;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.PageModules.PageKeyPhrase
{
	#region Local TraceSwitch 
	public class PageKeyTrace : ADNTraceSwitch
	{
		static public ADNTraceSwitch	Sw	=	new ADNTraceSwitch("PageKeyTrace","Special Trace Switch for PageKeyPhrase Trace");
	}
	#endregion Local TraceSwitch 

    public class AStr
    {
        public const string PKPStyle       =   "PKP_STYLE";
        public const string PKPCssClass    =   "PKP_CSSCLASS";
    }
    /// <summary>
    /// Initializer class for PageKeyPhrase 
    /// </summary>
    public class PageKeyPhraseSI : PortalModuleControlSI
    {
        public PageKeyPhraseSI(ModuleSettingsDictionary bSettings,ISettingsOwner pm) : base()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageKeyPhraseSI Ctor BEG.",ModuleTraceSwitch.Sw.Info);
            InitSettings(bSettings,pm);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageKeyPhraseSI Ctor END.",ModuleTraceSwitch.Sw.Info);
        }
 
        public override void InitSettings(ModuleSettingsDictionary bSettings,ISettingsOwner pm)
        {             
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageKeyPhraseSI InitSettings BEG.",ModuleTraceSwitch.Sw.Info);
            
            base.InitSettings(bSettings,pm);

            string extgrp                   =   pm.ExtendedResourcesGroup;


            SettingItemSpecial Field_id	    =   new SettingItemSpecial(AStr.PKPStyle,new StringDataType());
            Field_id.Order                  =   10;
            Field_id.ExtendedGroupName      =   extgrp;
            Field_id.Description            =   "Style to apply to the SPAN element.";
            Field_id.EnglishName            =   "Style";
            bSettings.AddSetting(Field_id);

            Field_id	                    =   new SettingItemSpecial(AStr.PKPCssClass,new StringDataType());
            Field_id.Order                  =   20;
            Field_id.ExtendedGroupName      =   extgrp;
            Field_id.Description            =   "Css class to apply to SPAN element.";
            Field_id.EnglishName            =   "Css class";
            bSettings.AddSetting(Field_id);

            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]PageKeyPhraseSI InitSettings END.",ModuleTraceSwitch.Sw.Info);
        }
    }

    public partial class PageKeyPhrase : PortalModuleControl
    {

		#region General Implementation

        public override Guid GuidID 
		{
			get
			{
				return new Guid("{ED58A5FB-D041-4a4b-826E-654250B61E7C}");
			}
		}

		#endregion

        /// <summary>
        /// Ctor
        /// </summary>
        public PageKeyPhrase()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose || MonitoringTrace.Sw.TraceVerbose )
                Trace2.WriteLine("[V]Monitoring Ctor BEG.",( ModuleTraceSwitch.Sw.TraceVerbose ) ? ModuleTraceSwitch.Sw.Info : MonitoringTrace.Sw.Info);

            if ( ModuleTraceSwitch.Sw.TraceVerbose || PageKeyTrace.Sw.TraceVerbose )
                Trace2.WriteLine("[V]PageKeyTrace Ctor BEG.",( ModuleTraceSwitch.Sw.TraceVerbose ) ? ModuleTraceSwitch.Sw.Info : PageKeyTrace.Sw.Info);
        }

        public override string ExtendedResourcesGroup 
		{
            get
            {
       			const string extgrp             =   "PAGEKEYPHRASE";
                return extgrp;
            }
		}

        public override void InitPortalModuleControl(ModuleSettingsDictionary bSettings)
        {
            PortalModuleInitializer =   new PageKeyPhraseSI(bSettings,this);
        }

        /// <summary>
        /// Apply attributes in settings to label
        /// </summary>
        protected override void OnPreRender(EventArgs e)
        {
            string cssclassName         =   Settings[AStr.PKPCssClass].Value.ToString().Trim();
            if ( !string.IsNullOrEmpty(cssclassName) )
                KeyPhrase.CssClass      =   cssclassName;
            string strstyle             =   Settings[AStr.PKPStyle].Value.ToString().Trim();
            if ( !string.IsNullOrEmpty(strstyle) )
                KeyPhrase.NewTextStyle  =   strstyle;
            base.OnPreRender(e);
        }
	}
}